local username = KEYS[1]
local timeWindow = tonumber(ARGV[1])

-- 构造限制访问次数的key
local accessKey = "short-link:user-flow-control:" .. username

-- 原子递增访问次数，并获取递增后的值
local currentAccessCount = redis.call("INCR", accessKey)

-- 如果返回自增为 1就证明是新的数据
-- 设置键的过期时间
if currentAccessCount == 1 then
    redis.call("EXPIRE", accessKey, timeWindow)
end

return currentAccessCount

